home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / DOpus_SDK_5.5 / docs / modules.ReadMe < prev    next >
Text File  |  1996-09-05  |  21KB  |  469 lines

  1. TABLE OF CONTENTS
  2.  
  3.  
  4.                                Directory Opus 5
  5.  
  6.                           External Module Definition
  7.  
  8.  
  9.  
  10.  
  11. 1. Introduction
  12. 2. Main module entry point
  13. 3. Second module entry point
  14. 4. Module identification
  15. 5. Function definitions
  16. 6. Standard startup code
  17. 7. Module callback function
  18.  
  19.  
  20. 1. Directory Opus 5 supports two types of "external modules". This document
  21. describes the main type, an AmigaDos library file. The other type, ARexx
  22. modules, are described in the main Opus 5 documentation.
  23.  
  24.     Library-based modules are located in the DOpus5:Modules/ directory, and
  25. are identified by the ".module" suffix. They are standard AmigaDos libraries,
  26. with two compulsory entry points. They main contain any other entry points you
  27. want, but the first two are required to work with Opus.
  28.  
  29.     The example code supplied with the SDK illustrates how to create an Opus
  30. module. While the supplied code is designed for SAS/C, it would be easy to
  31. adapt it to any other C compiler.
  32.  
  33.  
  34. 2. The main entry point to the module is a function called Module_Entry().
  35. The prototype for this function is as follows:
  36.  
  37.         long Module_Entry(  register __a0 char *args,
  38.                             register __a1 struct Screen *screen,
  39.                             register __a2 IPCData *ipc,
  40.                             register __a3 IPCData *mainipc,
  41.                             register __d0 ULONG mod_id,
  42.                             register __d1 EXT_FUNC(callback)  );
  43.  
  44.     This function must be at offset -0x1e in the library, and take parameters
  45. in the specified registers.
  46.  
  47.     You should never call this function yourself; it is called by Opus when
  48. the user runs one of the commands in your module. The parameters to the
  49. Module_Entry() function are as follows:
  50.  
  51.         args     - null-terminated argument string, contains any arguments the
  52.                    user supplied for the command
  53.  
  54.         screen   - main Opus screen pointer, you should open any requesters
  55.                    on this screen
  56.  
  57.         ipc      - a pointer to your IPCData structure - Opus launches each
  58.                    module command as a new process
  59.  
  60.         mainipc  - a pointer to the main IPCData structure for Opus
  61.  
  62.         mod_id   - the ID code of the command selected by the user
  63.  
  64.         callback - address of Opus callback function (see below)
  65.  
  66.  
  67. 3. The second entry point is a function that the module uses to identify
  68. itself. When Opus starts up it scans the contents of the modules directory,
  69. and calls this function in each of the modules.
  70.  
  71.     The standard modinit.o module startup code supplies this function for you.
  72. It is not recommended that you change it. If you need to supply your own
  73. function, the prototype is as follows :
  74.  
  75.         APTR Module_Identify(  register __d0 long num  );
  76.  
  77.     This function must be at offset -0x24 in the library. "num" is the command
  78. ID number that Opus is enquiring about. If "num" is equal to -1, you must
  79. return a pointer to the ModuleInfo structure for the module. If "num" is equal
  80. to a valid command ID code, you must return a pointer to a description string
  81. for that command. If "num" is an invalid value, you must return 0.
  82.  
  83.  
  84. 4. The contents of the module are identified with a ModuleInfo structure. All
  85. fields of the ModuleInfo structure must be initialised. The meaning of the
  86. fields is as follows:
  87.  
  88.         ver            - Module version number (for your own use)
  89.         name           - pointer to module name, including ".module" suffix
  90.         locale_name    - name of locale catalog for the module. This is opened
  91.                          automatically by the standard modinit.o startup code,
  92.                          which you should use.
  93.         flags          - Module flags, see below
  94.         function_count - The number of functions in this module
  95.         function       - The definition of the first function
  96.  
  97.     Module flag values (for the "flags" field) are as follows:
  98.  
  99.         MODULEF_CALL_STARTUP  - If this flag is specified, Opus will run
  100.                                 your module automatically on startup, with
  101.                                 the special "mod_id" value of FUNCID_STARTUP
  102.  
  103.         MODULEF_STARTUP_SYNC  - If MODULEF_CALL_STARTUP is also specified,
  104.                                 this flag causes Opus to wait for your
  105.                                 module to return from the startup call before
  106.                                 continuing
  107.  
  108.     The ModuleInfo structure contains room for only one function definition.
  109. If your module contains more than one function, the additional ModuleFunction
  110. structures MUST follow the ModuleInfo structure in memory. You must provide as
  111. many ModuleFunction structures are were specified in the "function_count"
  112. field of the ModuleInfo structure. For example,
  113.  
  114.         // Module definition, includes first function
  115.         ModuleInfo
  116.             module_info={
  117.                 1,                  // Version
  118.                 "example.module",   // Module name
  119.                 "example.catalog",  // Catalog name
  120.                 0,                  // Flags
  121.                 2,                  // Number of functions
  122.                 {0,"Example1",MSG_EXAMPLE1_DESC,0,0}};
  123.  
  124.         // Second function definition follows immediately on
  125.         ModuleFunction
  126.             module_func_2={
  127.                  1,"Example2",MSG_EXAMPLE2_DESC,0,0};
  128.  
  129.  
  130.  
  131. 5. The ModuleFunction structure is used to define each command that the
  132. module provides. The first function is defined with a ModuleFunction structure
  133. embedded in the ModuleInfo; additional commands must be defined after that.
  134. All fields of the ModuleFunction structure must be initialised, as follows:
  135.  
  136.         id        - command ID code. This value is passed as the "mod_id"
  137.                     parameter to the Module_Entry() function
  138.  
  139.         name      - name of the function. This is the actual command name
  140.                     that will be used to invoke this command
  141.  
  142.         desc      - locale string ID for the function description. This is the
  143.                     ID of the string in the catalog for this module that is
  144.                     used to describe this command in the popup command list.
  145.  
  146.         flags     - command flags, see below
  147.  
  148.         template  - command template (in ReadArgs() format). This string is
  149.                     displayed in the popup argument list in Opus function
  150.                     editors, but is not actually parsed by Opus. You will
  151.                     need to use the ParseArgs() routine on the "args"
  152.                     parameter in the Module_Entry() function.
  153.  
  154.     ModuleFunction flags are as follows:
  155.  
  156.         FUNCF_NEED_SOURCE    - set if your module requires a valid source
  157.                                directory - if one is not available, your
  158.                                command will not be launched
  159.  
  160.         FUNCF_NEED_DEST      - set if your module requires a valid destination
  161.                                directory
  162.  
  163.         FUNCF_NEED_FILES     - set if you need there to be selected files
  164.  
  165.         FUNCF_NEED_DIRS      - set if you need selected directories
  166.  
  167.         FUNCF_CAN_DO_ICONS   - set if you can operate on icons as well as
  168.                                normal files/directories
  169.  
  170.         FUNCF_SINGLE_SOURCE  - set if you can only operate on a single source
  171.                                lister
  172.  
  173.         FUNCF_SINGLE_DEST    - set if you can only operate on a single
  174.                                destination lister
  175.  
  176.         FUNCF_WANT_DEST      - set if you want a destination directory, but
  177.                                don't require one
  178.  
  179.         FUNCF_WANT_SOURCE    - set if you want a source directory, but don't
  180.                                require one
  181.  
  182.         FUNCF_WANT_ENTRIES   - set in conjunction with FUNCF_NEED_FILES or
  183.                                FUNCF_NEED_DIRS, to specify that you want those
  184.                                items but don't require them
  185.  
  186.         FUNCF_PRIVATE        - the function is private, it won't show up in
  187.                                the popup command list
  188.  
  189.  
  190. 6. It is highly recommended that you link with the standard module startup
  191. code (modinit.o) when creating modules. This code contains the
  192. Module_Identify() function, and automatically initialises several library bases
  193. which you may need. See the <dopus/modules.h> file for more information on
  194. this file.
  195.  
  196.  
  197. 7. The "callback" parameter to the Module_Entry() function provides the
  198. address of a callback function within Opus. This function allows you to access
  199. information that your module command may need. The callback function is
  200. defined as follows:
  201.  
  202.         ULONG callback(     register __d0 ULONG command,
  203.                             register __a0 APTR handle,
  204.                             register __a1 APTR packet   );
  205.  
  206.         command     - the callback command, see below for the list
  207.  
  208.         handle      - the callback handle. You must pass the value of
  209.                       IPCDATA(ipc) for this parameter ("ipc" is the argument
  210.                       passed to the Module_Entry() function)
  211.  
  212.         packet      - a command-specific packet
  213.  
  214.     Following is the list of callback commands. Each command takes a packet
  215. specific to it.
  216.  
  217.  
  218.         Command : EXTCMD_GET_SOURCE
  219.         Purpose : Returns the current source path
  220.         Packet  : char path[256]
  221.         Returns : struct path_node *path
  222.         Notes   : The packet is a pointer to a 256 character buffer, into
  223.                   which the current source path will be copied. The return
  224.                   value is a pointer to a path_node structure, which can be
  225.                   used with other callback commands. This structure is
  226.                   READ ONLY!
  227.  
  228.         Command : EXTCMD_END_SOURCE
  229.         Purpose : Finishes and cleans up current source path
  230.         Packet  : Set to 0
  231.         Returns : <none>
  232.         Notes   : Call this command if you are aborting early and do not
  233.                   wish to process further source paths.
  234.  
  235.         Command : EXTCMD_NEXT_SOURCE
  236.         Purpose : Gets the next source path
  237.         Packet  : char path[256]
  238.         Returns : struct path_node *path
  239.         Notes   : Call this command when you have finished with the first
  240.                   source path and want to move onto the next one. The
  241.                   return value is NULL if there are no more source paths.
  242.  
  243.         Command : EXTCMD_UNLOCK_SOURCE
  244.         Purpose : Unlock source listers
  245.         Packet  : <none>
  246.         Returns : <none>
  247.         Notes   : When your module command is called, any source listers
  248.                   are locked automatically. Call this command when you want
  249.                   to unlock them (they are unlocked automatically when
  250.                   your module returns).
  251.  
  252.         Command : EXTCMD_GET_DEST
  253.         Purpose : Returns the next destination path
  254.         Packet  : char path[256]
  255.         Returns : struct path_node *path
  256.         Notes   : The packet is a pointer to a 256 character buffer, into
  257.                   which the current destination path will be copied. The
  258.                   return value is a handle to the path, which can be used with
  259.                   other callback commands. Call this command repeatedly to
  260.                   move through the destination paths. When all the destination
  261.                   paths have been used, this command will return NULL. If you
  262.                   call this command again, it will will start again with the
  263.                   first destination path.
  264.  
  265.         Command : EXTCMD_END_DEST
  266.         Purpose : Ends the current destination path
  267.         Packet  : FALSE to abort, TRUE to continue
  268.         Returns : <none>
  269.         Notes   : You must call this command when you have finished with one
  270.                   destination path, prior to calling EXTCMD_GET_DEST.
  271.  
  272.         Command : EXTCMD_GET_ENTRY
  273.         Purpose : Get the next entry to work with
  274.         Packet  : <none>
  275.         Returns : struct function_entry {
  276.                     struct MinNode      node;   // Node
  277.                     char                *name;  // File name
  278.                     APTR                entry;  // Not used
  279.                     short               type;   // Type; <0 = file, >0 = dir
  280.                     short               flags;  // Not used
  281.                   };
  282.         Notes   : This returns a pointer to the next entry in the current
  283.                   source path. This structure is READ ONLY! Use the "name"
  284.                   field to get the entry name.
  285.  
  286.         Command : EXTCMD_END_ENTRY
  287.         Purpose : Finish with specific entry
  288.         Packet  : struct endentry_packet {
  289.                     struct function_entry   *entry;     // Entry to end
  290.                     BOOL                    deselect;   // TRUE for deselect
  291.                   };
  292.         Returns : <none>
  293.         Notes   : Call this command when you have finished working with one
  294.                   entry and wish to move on to the next. "entry" must be set
  295.                   to the pointer that was returned by EXTCMD_GET_ENTRY.
  296.                   Set "deselect" to TRUE to have the entry deselected in the
  297.                   lister.
  298.  
  299.         Command : EXTCMD_RELOAD_ENTRY
  300.         Purpose : Marks an entry to be reloaded
  301.         Packet  : struct function_entry *entry;
  302.         Returns : <none>
  303.         Notes   : This command marks the specified entry to be reloaded.
  304.                   When the function finishes, the entry will be reloaded to
  305.                   update any changes that your module might have made to
  306.                   it.
  307.  
  308.         Command : EXTCMD_REMOVE_ENTRY
  309.         Purpose : Marks an entry to be reloaded
  310.         Packet  : struct function_entry *entry;
  311.         Returns : <none>
  312.         Notes   : This command marks the specified entry to be removed.
  313.                   When the function finishes, the entry will be removed
  314.                   from the lister it is in.
  315.  
  316.         Command : EXTCMD_ENTRY_COUNT
  317.         Purpose : Returns total count of entries
  318.         Packet  : <none>
  319.         Returns : long entry_count;
  320.         Notes   : Returns the number of selected entries for the function.
  321.  
  322.         Command : EXTCMD_ADD_FILE
  323.         Purpose : Adds a file to a lister
  324.         Packet  : struct addfile_packet {
  325.                     char                 *path;     // Path to add file to
  326.                     struct FileInfoBlock *fib;      // FileInfoBlock to add
  327.                     APTR                 lister;    // Lister pointer
  328.                   };
  329.         Returns : <none>
  330.         Notes   : Allows you to add a file or directory to a lister. The path
  331.                   field points to the full path of the file to add. fib is an
  332.                   initialised FileInfoBlock which is used to create the file
  333.                   entry. The lister pointer is found in the path_node
  334.                   structure, which is obtained via a call to EXTCMD_GET_SOURCE
  335.                   or EXTCMD_GET_DEST. The display is not updated until you
  336.                   call EXTCMD_DO_CHANGES, or your function returns.
  337.  
  338.         Command : EXTCMD_DEL_FILE
  339.         Purpose : Delete a file from a lister
  340.         Packet  : struct delfile_packet {
  341.                     char    *path;      // Path file is in
  342.                     char    *name;      // Filename to delete
  343.                     APTR    lister;     // Lister pointer
  344.                   };
  345.         Returns : <none>
  346.         Notes   : This removes the specified file from any listers it is
  347.                   current shown in. The file itself is not deleted, only the
  348.                   display of it in the lister. The display is not updated
  349.                   until you call EXTCMD_DO_CHANGES, or your function returns.
  350.  
  351.         Command : EXTCMD_LOAD_FILE
  352.         Purpose : Load a new file in a lister
  353.         Packet  : struct loadfile_packet {
  354.                     char    *path;      // Path file is in
  355.                     char    *name;      // Name of file
  356.                     short   flags;      // Flags
  357.                     short   reload;     // Reload existing file
  358.                   };
  359.         Returns : <none>
  360.         Notes   : This command is similar to EXTCMD_ADD_FILE except that it
  361.                   Examines() the file and supplies the FileInfoBlock
  362.                   automatically. 'path' is the full path of the file and
  363.                   'name' is the file name. The only valid flag at this time
  364.                   is LFF_ICON, which indicates that the icon (.info) of the
  365.                   supplied file is to be loaded instead of the file itself.
  366.                   If 'reload' is set to TRUE, an existing file will be
  367.                   reloaded (ie the old entry in the lister will be removed).
  368.  
  369.         Command : EXTCMD_DO_CHANGES
  370.         Purpose : Perform file changes in listers
  371.         Packet  : <none>
  372.         Returns : <none>
  373.         Notes   : This command causes any changes made to listers by the
  374.                   EXTCMD_ADD_FILE, EXTCMD_DEL_FILE and EXTCMD_LOAD_FILE
  375.                   commands to be displayed. If your function returns without
  376.                   calling this command, the changes are displayed
  377.                   automatically.
  378.  
  379.         Command : EXTCMD_CHECK_ABORT
  380.         Purpose : Check abort status in lister
  381.         Packet  : <undefined>
  382.         Returns : BOOL
  383.         Notes   : This command returns TRUE if your 'function' has been
  384.                   aborted by the user. This could have occurred because the
  385.                   user pressed escape or clicked the close button on a lister,
  386.                   or quit the program.
  387.  
  388.         Command : EXTCMD_GET_WINDOW
  389.         Purpose : Get a lister's window pointer
  390.         Packet  : struct path_node *path
  391.         Returns : struct Window *window
  392.         Notes   : Returns a pointer to the Window for the lister specified by
  393.                   the path_node structure. This is useful if you want to open
  394.                   a requester over a lister window.
  395.  
  396.         Command : EXTCMD_GET_HELP
  397.         Purpose : Get help on a topic
  398.         Packet  : char *topic
  399.         Returns : <none>
  400.         Notes   : This command causes Opus to open the AmigaGuide help file and
  401.                   search for the named topic.
  402.  
  403.         Command : EXTCMD_GET_PORT
  404.         Purpose : Get ARexx port name
  405.         Packet  : char name[40]
  406.         Returns : <none>
  407.         Notes   : This command copies the name of the Opus ARexx port into the
  408.                   supplied buffer.
  409.  
  410.         Command : EXTCMD_GET_SCREEN
  411.         Purpose : Get public screen name
  412.         Packet  : char name[40]
  413.         Returns : <none>
  414.         Notes   : This command copies the name of the Opus public screen into
  415.                   the supplied buffer.
  416.  
  417.         Command : EXTCMD_REPLACE_REQ
  418.         Purpose : Shows a "file exists - replace?" requester
  419.         Packet  : struct replacereq_packet {
  420.                     struct Window        *window;   // Window to open over
  421.                     struct Screen        *screen;   // Screen to open on
  422.                     IPCData              *ipc;      // Process IPC pointer
  423.                     struct FileInfoBlock *file1;    // First file information
  424.                     struct FileInfoBlock *file2;    // Second file information
  425.                     short                flags;     // Set to 0 for now
  426.                   };
  427.         Returns : Result of requester; REPLACE_ABORT for abort,
  428.                   REPLACE_LEAVE for skip or REPLACE_REPLACE for replace.
  429.                   If the REPLACEF_ALL flag is set, it indicates an "All"
  430.                   gadget (eg Skip All, Replace All)
  431.  
  432.         Command : EXTCMD_GET_SCREENDATA
  433.         Purpose : Get information about the Opus display
  434.         Packet  : <none>
  435.         Returns : struct DOpusScreenData {
  436.                     struct Screen   *screen;        // Pointer to Opus screen
  437.                     struct DrawInfo *draw_info;     // DrawInfo structure
  438.                     USHORT          depth;          // Depth of screen
  439.                     USHORT          pen_alloc;      // Pen allocation flag
  440.                     USHORT          pen_array[16];  // User pen array
  441.                     USHORT          pen_count;      // Number of pens;
  442.                   };
  443.         Notes   : Returns a structure with useful information about the Opus
  444.                   screen. This structure is READ ONLY!
  445.                   Call EXTCMD_FREE_SCREENDATA to free it.
  446.  
  447.         Command : EXTCMD_FREE_SCREENDATA
  448.         Purpose : Free a DOpusScreenData structure
  449.         Packet  : struct DOpusScreenData *
  450.         Returns : <none>
  451.         Notes   : Frees the result of an EXTCMD_GET_SCREENDATA call
  452.  
  453. `       Command : EXTCMD_SEND_COMMAND
  454.         Purpose : Send an ARexx command to DOpus
  455.         Packet  : struct command_packet {
  456.                     char    *command;       // Command to send
  457.                     ULONG   flags;          // Command flags
  458.                     char    *result;        // Result pointer
  459.                     ULONG   rc;             // Result code
  460.                   };
  461.         Returns : TRUE if the message was sent
  462.         Notes   : This command allows you to send an ARexx instruction
  463.                   directly to the Opus ARexx port. Set the COMMANDF_RESULT
  464.                   flag if you want a result string returned; if one is,
  465.                   the 'result' field of the packet will contain a pointer
  466.                   to it. You MUST call FreeVec() on this pointer when you
  467.                   have finished with the result.
  468.  
  469.